package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

type myConfig struct {
	RunProduct bool
	Port       string
	Url        string
	Path       string
}

var Conf myConfig

func init() {
	viper.SetDefault("runProduct", true)
	viper.SetDefault("port", "80")
	viper.SetDefault("url", "/")
	viper.SetDefault("path", "webfs")
	viper.SetConfigName("conf")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(".")
	if err := viper.ReadInConfig(); err != nil {
		if _, ok := err.(viper.ConfigFileNotFoundError); ok {
			viper.WriteConfigAs("./conf.yaml")
		} else {
			// config file was found but another error was produced
		}
	}
	viper.Unmarshal(&Conf)
}

func main() {
	if Conf.RunProduct {
		gin.SetMode(gin.ReleaseMode)
	}
	server := gin.Default()
	server.StaticFS(Conf.Url, http.Dir(Conf.Path))
	server.Run(":" + Conf.Port)
}
